package com.zuorenke.help;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;

/**
 * @author Z.R.K
 * @description
 * @create 2019-04-13 11:42:15
 **/
public class DateUtils {
	private DateUtils() {
	}
	
	public static String[] getNearDay(int offset, String format){
		String[] days = new String[2];
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		Calendar c = Calendar.getInstance();
		c.add(Calendar.DAY_OF_MONTH, offset);
		days[0] = sdf.format(c.getTime());
		c.add(Calendar.DAY_OF_MONTH, offset + 1);
		days[1] = sdf.format(c.getTime());
		return days;
	}
	
	public static String getToday(String format){
		Calendar c = Calendar.getInstance();
		return toFormatString(c.getTimeInMillis(), format);
	}
	
	public static String toFormatString(Long timeMills, String format){
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(timeMills);
	}
	
	public static LocalDateTime strToDateTime(String dateTime, String format){
		DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(format);
		return LocalDateTime.parse(dateTime, dateFormatter);
	}
	
	public static Long getTimeSecond(LocalDateTime dateTime){
		return dateTime.toEpochSecond(ZoneOffset.UTC);
	}
	
	
	public static Long getTimeMills(LocalDateTime dateTime){
		return dateTime.toEpochSecond(ZoneOffset.UTC) * 1000;
	}
	
}
